import baseapi from '@/api/base'
import { getDataByParameter, getObjetInfoByPid, getCountByParameter, saveObjetInfo, deleteObjetInfo } from '@/utils/baserequest'
import storage from 'store'

const Base64 = require('js-base64').Base64

const api = {
  appContext: baseapi.biz,
  appAppId: baseapi.biz_app,
  appServer: 'xiaoShouChanPinMuLu',
  //商品库列表
  getStoreByConditions: 'keHuXinXi/by/findLikeExample',
  getStoreByConditionsCount: 'dataAreaUse/countLikeExample/',
  // saveInfo: 'xiaoShouChanPinMuLu/',
  getByConditions: 'xiaoShouChanPinMuLu/by/findLikeExample',
  getByConditionsCount: 'xiaoShouChanPinMuLu/countLikeExample/',
  //推送
  pushInfo: 'keHuXiaoShouChanPin/pushNew/',
}
export default api
//多条件查询商品包
export function getStoreByConditions (parameter, pagination, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const pa = {
    example: Base64.encode(JSON.stringify(Object.assign(parameter, { orgPid: storage.get('org') }))),
    pageSize: pagination.pageSize,
    currentPage: pagination.current,
    sidx: "",
    order: "0"
  }
  const url = api.appContext + api.getStoreByConditions
  const allheaders = appIdHeaders
  return getDataByParameter(url, pa, allheaders)
}
//多条件查询列表条数商品包
export function getStoreByConditionsCount (parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const example = Object.assign(parameter, { orgPid: storage.get('org') })
  const url = api.appContext + api.getStoreByConditionsCount
  const allheaders = appIdHeaders
  return getCountByParameter(url, Base64.encode(JSON.stringify(example)), allheaders)
}

//多条件查询
export function getByConditions (parameter, pagination, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const pa = {
    example: Base64.encode(JSON.stringify(Object.assign(parameter, { orgPid: storage.get('org') }))),
    pageSize: pagination.pageSize,
    currentPage: pagination.current,
    sidx: "",
    order: "0"
  }
  const url = api.appContext + api.getByConditions
  const allheaders = appIdHeaders
  return getDataByParameter(url, pa, allheaders)
}
//多条件查询列表条数
export function getByConditionsCount (parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const example = Object.assign(parameter, { orgPid: storage.get('org') })
  const url = api.appContext + api.getByConditionsCount
  const allheaders = appIdHeaders
  return getCountByParameter(url, Base64.encode(JSON.stringify(example)), allheaders)
}
//新增和修改
export function saveInfo (parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer + '/'
  const allheaders = appIdHeaders
  return saveObjetInfo(url, parameter, allheaders)
}

// 通过pid得到信息通用请求:get请求
export function getInfoByPid (parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer
  const allheaders = appIdHeaders
  return getObjetInfoByPid(url, parameter, allheaders)
}


//上传厂家证照
export function saveSellerLicense (parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer + '/'
  const allheaders = appIdHeaders
  return saveObjetInfo(url, parameter, allheaders)
}

// 通过pid得到厂家证照
export function getLicenseByPid (parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer
  const allheaders = appIdHeaders
  return getObjetInfoByPid(url, parameter, allheaders)
}
// 推送
export function pushInfo (parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.pushInfo
  const allheaders = appIdHeaders
  return postInfo(url, parameter, allheaders)
}







